<template>
  <section>
    <div v-show="showBody">
      <XdoCard :bordered="false">
        <div ref="area_head">
          <XdoBreadCrumb show-icon>
            <XdoButton type="primary" class="dc-margin-right" :loading="searchLoading" @click="handleSearchSubmit">查询</XdoButton>
            <XdoButton type="warning" class="dc-margin-right" @click="handleShowSearch">查询条件</XdoButton>
          </XdoBreadCrumb>
        </div>
        <div ref="area_search" >
          <div v-show="showSearch">
            <div class="separateLine"></div>
            <DcDecLogListSearch ref="listSearch"></DcDecLogListSearch>
          </div>
        </div>
      </XdoCard>
      <XdoCard :bordered="false">
        <div class="action" ref="area_actions">
          <template v-for="item in actions">
            <XdoButton v-if="item.needed === true" :type="item.type" :disabled="item.disabled" :loading="item.loading" style="font-size: 12px" :class="item.key"
                    @click="item.click" :key="item.label">
              <Icon :type="item.icon" size="22" class="xdo-icon"/>{{ item.label }}</XdoButton>&nbsp;
          </template>
        </div>
      </XdoCard>
      <XdoCard :bordered="false">
        <!--@on-row-dblclick="handleRowDblClick"-->
        <XdoTable class="dc-table" ref="table" :columns="gridConfig.gridColumns" :height="dynamicHeight"
                 :data="gridConfig.data" :loading="tableLoading" stripe :border="gridConfig.data.length > 0" @on-selection-change="handleSelectionChange"></XdoTable>
        <div ref="area_page">
          <XdoPage class="dc-page" :current="pageParam.page" :page-size='pageParam.limit' :total="pageParam.dataTotal" show-total show-sizer
                   @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="[15,20,30,40]"/>
        </div>
      </XdoCard>
    </div>
    <Modal v-model="logDetailModal" title="历史申报状态" @on-ok="ok" @on-cancel="cancel" width='1000'>
      <DcDecLogDetailList ref='child' :head-id='headId'></DcDecLogDetailList>
    </Modal>

    <DcDecLogEdit v-if="!showBody" @onEditBack="editBack" :editConfig="editConfig"></DcDecLogEdit>
  </section>
</template>
<script>
  import DcDecLogListSearch from './DcDecLogListSearch'
  import DcDecLogEdit from './DcDecLogEdit'
  import { jx_bill_testUri } from '@/api'
  import { getColumnsByConfig  } from '@/common'
  import { columnsConfig,columns  } from './dcDecLogColumns'
  import { commonProcess } from '@/view/jx_bill_test-common'
  import { editStatus } from '@/view/jx_bill_test-common/constant'
  import DcDecLogDetailList from '../../logDetailManage/dcDecLogDetail/DcDecLogDetailList'
  export default {
    name: 'DcDecLogList',
    components: {
      DcDecLogListSearch,
      DcDecLogEdit,
      DcDecLogDetailList
    },
    mixins: [ columns, commonProcess ],
    props: {
      headId: {type: String, default: ''},
      operationStatus: { type: String, default: editStatus.SHOW },
    },
    data() {
      return {
        logDetailModal:false,
        showBody: true,
        hasChildTabs: true,
        actions: [
          { type: 'text', disabled: false, click: this.handleAdd, icon: 'ios-add', label: '新增', key:'xdo-btn-add', loading: false, needed: true },
          { type: 'text', disabled: false, click: this.handleDelete, icon: 'ios-trash-outline', label: '删除', key:'xdo-btn-delete', loading: false, needed: true },
        ],
      }
    },
    mounted() {

      this.editConfig.headId = this.headId
      this.editConfig.flag=this.flag
      this.gridConfig.gridColumns = getColumnsByConfig(this.totalColumns, columnsConfig)
      this.refreshDynamicHeight()
      // this.getList()
      if (this.operationStatus === editStatus.SHOW) {
        this.actions = this.actions.filter(item => item.key === 'xdo-btn-download')
      }
    },
    methods: {
      getList() {
        this.tableLoading = true
        this.$nextTick(() => {
          let params = Object.assign({}, this.getSearchParams())
          // 其他参数赋值
          params.headId= this.headId
          //params.iEMark = "E"
          //params.emsNo = "E2325B0A0008"
          this.$http.post(jx_bill_testUri.xwManageHistoricalStateUrl.dcDecLog.list, params, {params: this.pageParam}).then(res => {
            if (res.data.success) {
              this.tableLoading = false
              this.gridConfig.data = res.data.data
              this.pageParam.dataTotal = res.data.total
            }
          }, () => {})
        })
      },
      handleEdit() {
          this.editConfig.editStatus = editStatus.EDIT
          this.editConfig.headId = this.gridConfig.selectData.sid
          this.editConfig.editData = this.gridConfig.selectData
          this.showBody = false
      },
      handleView() {
          this.editConfig.editStatus = editStatus.SHOW
          this.editConfig.headId = this.gridConfig.selectData.sid
          this.editConfig.editData = this.gridConfig.selectData
          this.showBody = false
      },
      handleAdd() {
          this.gridConfig.selectRows = []
          this.editConfig.editStatus = editStatus.ADD
          this.editConfig.editData = {}
          this.showBody = false
      },
      handleDelete() {
        this.doDelete(jx_bill_testUri.xwManageHistoricalStateUrl.dcDecLog.delete)
      },
      LogDetailListShow(){
        this.$refs.child.getList()
        this.logDetailModal=true
      },
      editBack(val) {
        if(val){
          this.showBody = true
          this.gridConfig.selectRows = []
          this.getList()
        }
      },
    }
  }
</script>
<style lang="less" scoped>
</style>
